package com.penghk.springbootdemo.controller;

import org.springframework.ui.Model;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.*;

@ControllerAdvice
public class MyControllerAdvice {

    @ExceptionHandler(value = Exception.class)
    public String ex(Exception e) {
        System.out.println(e.getMessage());
//        return "{\"error\":\"hello\"}";
        return "error";
    }

    @ModelAttribute
    public void addModel(Model model) {
        model.addAttribute("msg" , "额外信息");
    }

    @InitBinder
    public void initBinder(WebDataBinder binder) {
        binder.setDisallowedFields("id");
    }

}
